package com.bridgeQQ.client.control.commands
{    
	/**
	 * 该类用来支持respond,在info中可以传入respond的处理函数，在结果返回时，会
	 * 调用这些函数，处理函数只有一个参数，该参数包括该command执行后得到的结果信息，
	 * 放在respond字段内
	 * @author jiangjiang.li
	 * 
	 */    
	public class BaseRespond
	{
		protected var _info:Object;
		
		protected var target:Object;
		
		protected var params:Array;
		
		public function BaseRespond(info:Object, target:Object, ...params)
		{
			this._info = info;
			this.target  = target;
			this.params = params;
		}
		
		public function get info():Object
		{
			return this._info;
		}
		
		public function execute():void
		{
			
		}
		
		protected final function createRespondInfo(existError:Boolean, value:Object):void
		{
			var respond:Object = {result: !existError, value: value};
			info.respond = respond;
			if(!existError)
			{
				result();
				return;
			}
			fault();
		}
		
		
		private function result():void
		{
			var result:Function = info.result;
			if(result != null)
			{
				result(info);
			}
			var array:Array = info.results;
			for each(var item:Function in array)
			{
				item(info);
			}
		}
		
		private function fault():void
		{
			var fault:Function = info.fault;
			if(fault != null)
			{
				fault(info);
			}	
			var array:Array = info.fault;
			for each(var item:Function in array)
			{
				item(info);
			}		
		}
		
	}
}